#include "task_meter.h"
#include "bsp_usb.h"
#include "bsp_meter.h"

TaskHandle_t xHandleTaskMeter = NULL;
xSemaphoreHandle xMeterDataBinarySemaphore;

void vTaskMeter( void *pvParameters )
{
	xSemaphoreTake(xMeterDataBinarySemaphore, portMAX_DELAY );
  while(1)
	{
		xSemaphoreTake(xMeterDataBinarySemaphore, portMAX_DELAY );
		
		printf( "Wait Device In\n" );
		vTaskDelay(200 / portTICK_RATE_MS );
		while(1)
		{
			int8_t stat = USB_Analyze(); 
			if(stat == DATA_FINISH || stat == DISCONNECT || stat ==ENUM_ERROR)	
			{
				printf( "DISCONNECT | DATA_FINISH----------------------------\r\n" );
				USB_HostInit();   
				//vTaskDelay(100 / portTICK_RATE_MS );
				//NVIC_SystemReset();
				break;
			}
		}	
	}
	vTaskDelete(NULL);
}


